<#assign ctx=request.contextPath>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>管理后台</title>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link href="${ctx}/static/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="${ctx}/static/css/ace.min.css"/>
    <link rel="stylesheet" href="${ctx}/static/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="${ctx}/static/datacenter/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="${ctx}/static/css/ace-rtl.min.css"/>
    <link rel="stylesheet" href="${ctx}/static/css/ace-skins.min.css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="${ctx}/static/css/ace-ie.min.css"/>
    <![endif]-->
    <link rel="stylesheet" href="${ctx}/static/dlshouwen.grid.v1.2.1/dlshouwen.grid.min.css"/>
    <script src="${ctx}/js/ace-extra.min.js"></script>
    <!--[if lt IE 9]>
    <script src="${ctx}/js/html5shiv.js"></script>
    <script src="${ctx}/js/respond.min.js"></script>
    <![endif]-->
    <!-- jedate-->
    <link rel="stylesheet" href="${ctx}/static/jedate/skin/jedate.css"/>
    <script src="${ctx}/static/jedate/jedate.js"></script>
    <#include "/common.ftl"/>
</head>
<body>
    <#include "/head.ftl" />
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>
    <div class="main-container-inner">
        <a class="menu-toggler" id="menu-toggler" href="#">
            <span class="menu-text"></span>
        </a>
        <#include "/menu.ftl"/>
        <div class="main-content">
            <div class="breadcrumbs" id="breadcrumbs">
                <script type="text/javascript">
                    try {
                        ace.settings.check('breadcrumbs', 'fixed')
                    } catch (e) {
                    }
                </script>
                <ul class="breadcrumb">
                    <li>
                        <i class="icon-home home-icon"></i>
                        <a href="${ctx}/admin/index">首页</a>
                    </li>
                    <li><a href="#">店铺返现</a></li>
                    <li class="active">订单申请</li>
                </ul><!-- .breadcrumb -->

                <div class="nav-search" id="nav-search">
                    <form class="form-search">
								<span class="input-icon">
									<input type="text" placeholder="Search ..." class="nav-search-input"
                                           id="nav-search-input" autocomplete="off"/>
									<i class="icon-search nav-search-icon"></i>
								</span>
                    </form>
                </div><!-- #nav-search -->
            </div>

            <div class="page-content">
                <div class="page-header">
                    <div class="col-sm-12">
                        <label class="control-label col-sm-1 no-padding-right">开始时间</label>
                        <div class="col-sm-2">
                            <input class="form-control" name="stime" id="stime" type="text"
                                   placeholder="开始时间..."/>
                        </div>
                        <label class="control-label col-sm-1 no-padding-right">结束时间</label>
                        <div class="col-sm-2">
                            <input class="form-control" name="etime" id="etime" type="text"
                                   placeholder="结束时间..."/>
                        </div>
                        <label class="control-label col-sm-1 no-padding-right">玩法查询</label>
                        <div class="col-sm-2">
                            <input class="btn-upload" id="excelUpload" onchange="uploadExcel()" type="file"
                                   accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
                            />
                        </div>
                        <label class="control-label col-sm-1 no-padding-right">玩法查询</label>
                        <div class="col-sm-2">
                            <input class="form-control" name="orderId" id="orderId" type="text" placeholder="订单Id"/>
                        </div>
                        <label class="control-label col-sm-1 no-padding-right">玩法查询</label>
                        <div class="col-sm-2">
                            <input class="form-control" name="taobaoId" id="taobaoId" type="text" placeholder="淘宝id"/>
                        </div>
                        <label class="control-label col-sm-1 no-padding-right">玩法查询</label>
                        <div class="col-sm-2">
                            <select class="form-control" name="status" id="status">
                                <option value="">---查看所有---</option>
                                <option value="0">已提交</option>
                                <option value="1">已审核</option>
                                <option value="2">已支付</option>
                            </select>
                        </div>
                        <div class="col-sm-1">
                            <button id="btnSearch" class="btn btn-primary btn-sm" type="button">
                                <i class="fa fa-search"></i>查询
                            </button>
                        </div>
                    </div>
                </div>
            </div><#--/ .page-content-->

            <div class="row">
                <div class="col-sm-12">
                    <div class="widget-box transparent ui-sortable-handle"
                         style="opacity: 1; z-index: 0;">
                        <div class="widget-header">
                        <#--  <h5 class="widget-title lighter"> 订单申请</h5>-->
                        </div>
                        <div class="widget-body" style="display: block;">
                            <div class="widget-main padding-6 no-padding-left no-padding-right">
                                <input id="pageNum" type="hidden" value="${page.pageNum }">
                                <input id="pageSize" type="hidden" value="${page.pageSize }">
                                <input id="orderByColumn" type="hidden" value="${page.orderByColumn }">
                                <input id="orderByType" type="hidden" value="${page.orderByType }">
                                <div id="dtGridContainer" class="dlshouwen-grid-container"></div>
                                <div id="dtGridToolBarContainer" class="dlshouwen-grid-toolbar-container"></div>
                            </div>
                        </div>
                    </div>
                </div><!-- /.col-sm-12 -->
            </div><!-- /.row -->
        </div><!-- /.main-content -->

        <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
            <i class="icon-double-angle-up icon-only bigger-110"></i>
        </a>
    </div><#--/.main-container-inner-->
</div> <#--/.main-container-inner-->
</body>
</html>

<script type="text/javascript">

    $(function () {
        jeDate({
            dateCell: '#stime',
            isinitVal: new Date(),
            //isinitVal:false,
            format: 'YYYY-MM-DD', // 分隔符可以任意定义，该例子表示只显示年月
            minDate: '1900-06-01', //最小日期
            maxDate: '2050-06-01' //最大日期
        });
        jeDate({
            dateCell: '#etime',
            isinitVal: new Date(),
            //isinitVal:false,
            format: 'YYYY-MM-DD', // 分隔符可以任意定义，该例子表示只显示年月
            minDate: '1900-06-01', //最小日期
            maxDate: '2050-06-01' //最大日期
        });

        var saveDate = new Date();
        saveDate.setDate(saveDate.getDate() + 1);
        var year = saveDate.getFullYear();
        var month = saveDate.getMonth() + 1 < 10 ? "0" + (saveDate.getMonth() + 1) : saveDate.getMonth() + 1;
        var date = saveDate.getDate() < 10 ? "0" + saveDate.getDate() : saveDate.getDate();
        var yesDate = year + "-" + month + "-" + date;
        //$('#stime').val(yesDate);
        $('#etime').val(yesDate);
    });
    var dtGridColumns = [
        {
            id: 'name',
            title: '用户昵称',
            type: 'string',
            columnClass: 'text-center',
            headerStyle: 'background:#00a2ca;color:white;'
        },
        {
            id: 'icon',
            title: '用户昵称',
            type: 'string',
            columnClass: 'text-center',
            headerStyle: 'background:#00a2ca;color:white;',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                return '<img src="' + value + '" style="width: 3.5em;height: 3.5em;border-radius: 8px" >';
            }
        },
        {
            id: 'order_id',
            title: '订单id',
            type: 'string',
            columnClass: 'text-center',
            headerStyle: 'background:#00a2ca;color:white;'
        },
        {
            id: 'money',
            title: '金额',
            type: 'string',
            columnClass: 'text-center',
            headerStyle: 'background:#00a2ca;color:white;'
        },
        {
            id: 'taobao_id',
            title: '淘宝号',
            type: 'string',
            columnClass: 'text-center',
            headerStyle: 'background:#00a2ca;color:white;'
        },
        {
            id: 'create_time',
            title: '订单提交时间',
            type: 'date',
            format: 'yyyy-MM-dd hh:mm:ss',
            columnClass: 'text-center',
            headerStyle: 'background:#00a2ca;color:white;'
        },
        {
            id: 'status',
            title: '订单状态',
            type: 'string',
            columnClass: 'text-center',
            headerStyle: 'background:#00a2ca;color:white;',
            resolution: function (value, record, column, grid, dataNo, columnNo) {

                if (value == 0) return '<span class=\"label label-sm label-info arrowed arrowed-righ \">已提交</span>';
                if (value == 1) return '<span class=\"label label-sm label-info arrowed arrowed-righ\" style="color: blue;">已审核</span>';
                if (value == 2) return '<span class=\"label label-sm label-info arrowed arrowed-righ red\">已发放</span>';
                return "";
            }
        },
        {
            id: 'order_id',
            title: '操作',
            type: 'string',
            columnClass: 'text-center',
            headerStyle: 'background:#00a2ca;color:white;',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                if (record.status == 2)
                    return "订单已完成";
                if (record.status == 1)
                    return '<button class="btn btn-primary btn-sm" style="border-radius: 5px;" onclick="checkSend(\'' + value + '\',2)">发放</button>';
                if (record.status == 0)
                    return '<button class="btn btn-success btn-sm" style="border-radius: 5px;" onclick="checkSend(\'' + value + '\',1)">审核</button>'
                            + '<button class="btn btn-primary btn-sm" style="border-radius: 5px;" onclick="checkSend(\'' + value + '\',2)">发放</button>';

            }
        }];
    var pageSize = $("#pageSize").val();
    pageSize = pageSize == 0 || pageSize == "" ? 10 : pageSize;

    var dtGridOption = {
        lang: 'zh-cn',
        ajaxLoad: true,
        check: false,
        loadURL: '${ctx}/shop/getOrderList',
        columns: dtGridColumns,
        gridContainer: 'dtGridContainer',
        toolbarContainer: 'dtGridToolBarContainer',
        exportFileName: '订单申请',
        pageSize: pageSize,
        pageSizeLimit: [10, 20, 50]
    };
    var grid = $.fn.dlshouwen.grid.init(dtGridOption);

    $(function () {
        if (null != $("#orderByColumn").val() && '' != $("#orderByColumn").val()) {
            grid.sortParameter.columnId = $("#orderByColumn").val();
            grid.sortParameter.sortType = $("#orderByType").val();
        }
        grid.parameters = new Object();
        var stime = $('#stime').val();
        var etime = $('#etime').val();
        var orderId = $('#orderId').val();
        var taobaoId = $('#taobaoId').val();
        var status = $('#status').val();
        var name = $('#name').val();
        grid.parameters['stime'] = stime;
        grid.parameters['etime'] = etime;
        grid.parameters['orderId'] = orderId;
        grid.parameters['taobaoId'] = taobaoId;
        grid.parameters['status'] = status;
        grid.parameters['name'] = name;
        grid.load();
        $("#btnSearch").click(customSearch);
    });

    /**
     * 自定义查询
     * 这里不传入分页信息，防止删除记录后重新计算的页码比当前页码小而导致计算异常
     */
    function customSearch() {
        var stime = $('#stime').val();
        var etime = $('#etime').val();
        var orderId = $('#orderId').val();
        var taobaoId = $('#taobaoId').val();
        var name = $('#name').val();
        var status = $('#status').val();
        grid.parameters = new Object();
        grid.parameters['stime'] = stime;
        grid.parameters['etime'] = etime;
        grid.parameters['orderId'] = orderId;
        grid.parameters['taobaoId'] = taobaoId;
        grid.parameters['status'] = status;
        grid.parameters['name'] = name;
        grid.refresh(true);
    }

    function checkSend(orderId, type) {
        if (orderId == null && orderId == undefined && orderId.length == 0) {
            layer.msg("非法提交！", {icon: 5});
            return
        }
        $.ajax({
            type: "POST",
            url: "${ctx}/shop/applyOrder",
            dataType: "json",
            data: {"orderId": orderId, "type": type},
            success: function (data) {
                if (data.success) {
                    layer.msg(data.message, {icon: 1});
                    //  customSearch();
                } else {
                    layer.msg(data.message, {icon: 5});
                }
            }
        });
    }

    /**订单导入*/
    function uploadExcel() {
        var uploadExcel = $('#excelUpload').val();
        if (uploadExcel == undefined || uploadExcel == '') {
            layer.msg("请选择上传的文件!", {icon: 5});
            return;
        } else if (uploadExcel.lastIndexOf(".xls") > 0 || uploadExcel.lastIndexOf(".xlsx") > 0) {//可判断以.xls和.xlsx结尾的excel
            var url = '${ctx}/shop/0nekeyImportOrder';
            /* var formData = new FormData($('#storeForms')[0]); */

            var formData = new FormData();
            formData.append('file', $('#excelUpload')[0].files[0]);

            sendAjaxRequest(url, formData);
        } else {
            layer.msg("只能上传Excel!", {icon: 5});
            return;
        }

    }

    function sendAjaxRequest(url, data) {
        $.ajax({
            url: url,
            type: 'POST',
            cache: false,
            data: data,
            contentType: false, //必须false才会避开jQuery对 formdata 的默认处理 , XMLHttpRequest会对 formdata 进行正确的处理
            processData: false,
            success: function (data) {

                var result = jQuery.parseJSON(data)
                if (result.state == 200) {
                    layer.msg("上传成功", {
                        icon: 6
                    });
                    /*  $(".page-content").empty();
                      $(".page-content").load( sys.rootPath + "/storeGoodsRecord/listUi.html");
  */
                } else {
                    layer.msg("上传失败", {
                        icon: 5
                    });

                }
            },
            error: function () {
                layer.msg("上传失败", {
                    icon: 5
                });
            }
        });
    }
</script>
